home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2011 November
/
CHIP_2011_11.iso
/
Programy
/
Inne
/
Gry
/
Carnage_Contest
/
scripts
/
CC Original
/
tools
/
Explosives.lua
< prev
next >
Wrap
Text File
|
2010-09-16
|
4KB
|
122 lines
--------------------------------------------------------------------------------
-- Weapon Explosives
-- Original Carnage Contest Weapon
-- Script by DC, September 2010, www.UnrealSoftware.de
--------------------------------------------------------------------------------
-- Setup Tables
if cc==nil then cc={} end
cc.explosives={}
cc.explosives.expl={}
-- Load & Prepare Ressources
cc.explosives.sfx_attack=loadsfx("throw.ogg") -- Attack Sound
cc.explosives.sfx_bounce=loadsfx("bounce.wav") -- Bounce
cc.explosives.gfx_wpn=loadgfx("buildings/explosives.bmp")
setmidhandle(cc.explosives.gfx_wpn)
--------------------------------------------------------------------------------
-- Weapon: Explosives
--------------------------------------------------------------------------------
cc.explosives.id=addweapon("cc.explosives","Explosives",cc.explosives.gfx_wpn,1,2) -- Add Weapon (1 use, first in round 2)
function cc.explosives.draw() -- Draw
-- HUD Positioning
if weapon_shots==0 then
hudpositioning(pos_build,cc.explosives.gfx_wpn,30,1,1,1)
end
end
function cc.explosives.attack(attack) -- Attack
if (weapon_shots<=0) and (weapon_position==1) then
-- No more weapon switching!
useweapon(0)
playsound(cc.explosives.sfx_attack)
weapon_shots=weapon_shots+1
createobject(cc.explosives.expl.id,weapon_x,weapon_y)
-- End Turn
endturn()
end
end
--------------------------------------------------------------------------------
-- Object: Explosives
--------------------------------------------------------------------------------
cc.explosives.expl.id=addobject("cc.explosives.expl",cc.explosives.gfx_wpn) -- Add Object
function cc.explosives.expl.setup(id,parameter)
if objects==nil then objects={} end
objects[id]={}
objects[id].sy=0
objects[id].timer=0
end
function cc.explosives.expl.draw(id,x,y)
-- Setup draw mode
setblend(blend_alpha)
setalpha(1)
setcolor(255,255,255)
setscale(1,1)
setrotation(0)
-- Draw
drawimage(cc.explosives.gfx_wpn,x,y)
end
function cc.explosives.expl.update(id,x,y)
-- Gravity influence on speed
objects[id].sy=objects[id].sy+getgravity()
-- Move (in substep loop for optimal collision precision)
msubt=math.ceil(math.abs(objects[id].sy)/15)
msuby=objects[id].sy/msubt
for i=1,msubt,1 do
y=y+msuby
-- Collision
if collision(cc.explosives.gfx_wpn,x,y,1,1,1,-1,id)==1 then
if (math.abs(objects[id].sy)>0.5) then playsound(cc.explosives.sfx_bounce) end
y=y-msuby
objects[id].sy=-objects[id].sy*0.3
msuby=-msuby*0.3
end
-- Water
if y>getwatery()+5 then
-- Effects
particle(p_waterhit,x,y)
playsound(sfx_hitwater1)
-- Remove
removeobject(id)
return
end
end
objectposition(id,x,y)
-- Explode (delayed)
if objects[id].timer>0 then
objects[id].timer=objects[id].timer+1
if objects[id].timer>=20 then
-- Destroy terrain
terrainexplosion(x,y,50,1)
-- Crater
grey=math.random(0,40)
if math.random(0,1)==1 then
terrainalphaimage(gfx_crater125,getobjectx(id),getobjecty(id),math.random(6,9)*0.1,grey,grey,grey)
else
terrainalphaimage(gfx_crater150,getobjectx(id),getobjecty(id),math.random(6,9)*0.1,grey,grey,grey)
end
-- Remove
removeobject(id)
-- Cause damage
arealdamage(x,y,140,80)
end
-- Fire Collision?
elseif firecollision(cc.explosives.gfx_wpn,x,y)>0 then
objects[id].timer=1
end
end
function cc.explosives.expl.damage(id,damage)
if objects[id].timer==0 then
objects[id].timer=1
end
end